From 09d62a652514ce494447febfebac16c3ef10ed84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marvin=20L=C3=B6bel?= Date: Fri, 16 Oct 2015 14:54:40 +0200 Subject: [PATCH] Made cargo derive more working directory locations from its Config --- src/bin/bench.rs | 4 ++-- src/bin/build.rs | 4 ++-- src/bin/clean.rs | 4 ++-- src/bin/doc.rs | 4 ++-- src/bin/fetch.rs | 4 ++-- src/bin/generate_lockfile.rs | 4 ++-- src/bin/locate_project.rs | 6 +++--- src/bin/package.rs | 4 ++-- src/bin/pkgid.rs | 4 ++-- src/bin/publish.rs | 4 ++-- src/bin/read_manifest.rs | 4 ++-- src/bin/run.rs | 4 ++-- src/bin/rustc.rs | 4 ++-- src/bin/test.rs | 4 ++-- src/bin/update.rs | 4 ++-- src/bin/verify_project.rs | 4 ++-- src/cargo/lib.rs | 5 ++++- src/cargo/ops/cargo_new.rs | 10 +++++----- src/cargo/ops/cargo_rustc/context.rs | 2 +- src/cargo/ops/cargo_rustc/engine.rs | 6 +++--- src/cargo/ops/registry.rs | 6 +++--- src/cargo/util/config.rs | 8 ++------ src/cargo/util/important_paths.rs | 8 ++------ src/cargo/util/process_builder.rs | 10 ++++++---- src/cargo/util/rustc.rs | 4 ++-- src/cargo/util/vcs.rs | 12 ++++++------ 26 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 7e658997d..4dc080a42 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Human, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -62,7 +62,7 @@ Compilation can be customized with the `bench` profile in the manifest. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); diff --git a/src/bin/build.rs b/src/bin/build.rs index 27bcf57b1..c291ba9c7 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -2,7 +2,7 @@ use std::env; use cargo::ops::CompileOptions; use cargo::ops; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::util::{CliResult, CliError, Config}; #[derive(RustcDecodable)] @@ -64,7 +64,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let opts = CompileOptions { config: config, diff --git a/src/bin/clean.rs b/src/bin/clean.rs index 8aea04d35..c06d657fe 100644 --- a/src/bin/clean.rs +++ b/src/bin/clean.rs @@ -2,7 +2,7 @@ use std::env; use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -40,7 +40,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::>()); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let opts = ops::CleanOptions { config: config, spec: &options.flag_package, diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 16fd12430..63a539ae6 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -52,7 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let mut doc_opts = ops::DocOptions { open_result: options.flag_open, diff --git a/src/bin/fetch.rs b/src/bin/fetch.rs index 6b2cb9d91..c9737571f 100644 --- a/src/bin/fetch.rs +++ b/src/bin/fetch.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::find_root_manifest_for_cwd; +use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] struct Options { @@ -36,7 +36,7 @@ all updated. pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(ops::fetch(&root, config).map_err(|e| { CliError::from_boxed(e, 101) })); diff --git a/src/bin/generate_lockfile.rs b/src/bin/generate_lockfile.rs index 29891f1c8..1e006bdf3 100644 --- a/src/bin/generate_lockfile.rs +++ b/src/bin/generate_lockfile.rs @@ -2,7 +2,7 @@ use std::env; use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::find_root_manifest_for_cwd; +use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] struct Options { @@ -30,7 +30,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::>()); try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); ops::generate_lockfile(&root, config) .map(|_| None).map_err(|err| CliError::from_boxed(err, 101)) diff --git a/src/bin/locate_project.rs b/src/bin/locate_project.rs index 4c870ba4d..e9fb43454 100644 --- a/src/bin/locate_project.rs +++ b/src/bin/locate_project.rs @@ -1,5 +1,5 @@ use cargo::util::{CliResult, CliError, human, ChainError, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct LocateProjectFlags { @@ -21,8 +21,8 @@ struct ProjectLocation { } pub fn execute(flags: LocateProjectFlags, - _: &Config) -> CliResult> { - let root = try!(find_root_manifest_for_cwd(flags.flag_manifest_path)); + config: &Config) -> CliResult> { + let root = try!(find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())); let string = try!(root.to_str() .chain_error(|| human("Your project path contains \ diff --git a/src/bin/package.rs b/src/bin/package.rs index 4d3b72b71..63edc3bae 100644 --- a/src/bin/package.rs +++ b/src/bin/package.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::find_root_manifest_for_cwd; +use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] struct Options { @@ -34,7 +34,7 @@ Options: pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); ops::package(&root, config, !options.flag_no_verify, options.flag_list, diff --git a/src/bin/pkgid.rs b/src/bin/pkgid.rs index abbe4e52f..b95294e0c 100644 --- a/src/bin/pkgid.rs +++ b/src/bin/pkgid.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -49,7 +49,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone())); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd())); let spec = options.arg_spec.as_ref().map(|s| &s[..]); let spec = try!(ops::pkgid(&root, spec, config).map_err(|err| { diff --git a/src/bin/publish.rs b/src/bin/publish.rs index 387daecd2..d70043c0c 100644 --- a/src/bin/publish.rs +++ b/src/bin/publish.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::find_root_manifest_for_cwd; +use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] struct Options { @@ -42,7 +42,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { .. } = options; - let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone())); + let root = try!(find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd())); ops::publish(&root, config, token, host, !no_verify).map(|_| None).map_err(|err| { CliError::from_boxed(err, 101) }) diff --git a/src/bin/read_manifest.rs b/src/bin/read_manifest.rs index 2539655f8..b25eedb0e 100644 --- a/src/bin/read_manifest.rs +++ b/src/bin/read_manifest.rs @@ -3,7 +3,7 @@ use std::error::Error; use cargo::core::{Package, Source}; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::sources::{PathSource}; #[derive(RustcDecodable)] @@ -29,7 +29,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> env::args().collect::>()); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let mut source = try!(PathSource::for_path(root.parent().unwrap(), config).map_err(|e| { CliError::new(e.description(), 1) diff --git a/src/bin/run.rs b/src/bin/run.rs index d765967dd..f05d63e3d 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Config, Human}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -52,7 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let (mut examples, mut bins) = (Vec::new(), Vec::new()); if let Some(s) = options.flag_bin { diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 924cfb636..72b8f71a5 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -2,7 +2,7 @@ use std::env; use cargo::ops::CompileOptions; use cargo::ops; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::util::{CliResult, CliError, Config}; #[derive(RustcDecodable)] @@ -67,7 +67,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let opts = CompileOptions { config: config, diff --git a/src/bin/test.rs b/src/bin/test.rs index 09981e0be..2029daa4c 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::util::{CliResult, CliError, Human, Config}; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; #[derive(RustcDecodable)] struct Options { @@ -68,7 +68,7 @@ Compilation can be configured via the `test` profile in the manifest. "; pub fn execute(options: Options, config: &Config) -> CliResult> { - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); diff --git a/src/bin/update.rs b/src/bin/update.rs index 75cac7a70..27842ba8d 100644 --- a/src/bin/update.rs +++ b/src/bin/update.rs @@ -2,7 +2,7 @@ use std::env; use cargo::ops; use cargo::util::{CliResult, CliError, Config}; -use cargo::util::important_paths::find_root_manifest_for_cwd; +use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(RustcDecodable)] struct Options { @@ -56,7 +56,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::>()); try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); - let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); + let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); let update_opts = ops::UpdateOptions { aggressive: options.flag_aggressive, diff --git a/src/bin/verify_project.rs b/src/bin/verify_project.rs index b4998282e..962a0340f 100644 --- a/src/bin/verify_project.rs +++ b/src/bin/verify_project.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::prelude::*; use std::process; -use cargo::util::important_paths::{find_root_manifest_for_cwd}; +use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::util::{CliResult, Config}; use rustc_serialize::json; use toml; @@ -37,7 +37,7 @@ pub fn execute(args: Flags, config: &Config) -> CliResult> { let mut contents = String::new(); let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into()); - let filename = match find_root_manifest_for_cwd(Some(filename)) { + let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) { Ok(manifest_path) => manifest_path, Err(e) => fail("invalid", &e.to_string()), }; diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 949e3c0e6..1c85c686b 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -97,7 +97,10 @@ fn process(mut callback: F) { let mut config = None; let result = (|| { - config = Some(try!(Config::new(shell(Verbose, Auto)))); + let cwd = try!(env::current_dir().chain_error(|| { + human("couldn't get the current directory of the process") + })); + config = Some(try!(Config::new(shell(Verbose, Auto), cwd))); let args: Vec<_> = try!(env::args_os().map(|s| { s.into_string().map_err(|s| { human(format!("invalid unicode in argument: {:?}", s)) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index c3a6e5acb..f64929a1f 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -97,15 +97,15 @@ fn strip_rust_affixes(name: &str) -> &str { name } -fn existing_vcs_repo(path: &Path) -> bool { - GitRepo::discover(path).is_ok() || HgRepo::discover(path).is_ok() +fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool { + GitRepo::discover(path, cwd).is_ok() || HgRepo::discover(path, cwd).is_ok() } fn mk(config: &Config, path: &Path, name: &str, opts: &NewOptions) -> CargoResult<()> { let cfg = try!(global_config(config)); let mut ignore = "target\n".to_string(); - let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap()); + let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap(), config.cwd()); if !opts.bin { ignore.push_str("Cargo.lock\n"); } @@ -119,11 +119,11 @@ fn mk(config: &Config, path: &Path, name: &str, match vcs { VersionControl::Git => { - try!(GitRepo::init(path)); + try!(GitRepo::init(path, config.cwd())); try!(paths::write(&path.join(".gitignore"), ignore.as_bytes())); }, VersionControl::Hg => { - try!(HgRepo::init(path)); + try!(HgRepo::init(path, config.cwd())); try!(paths::write(&path.join(".hgignore"), ignore.as_bytes())); }, VersionControl::NoVcs => { diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 89a2c1a08..caf5301d0 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -100,7 +100,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// specified as well as the exe suffix fn filename_parts(target: Option<&str>, cfg: &Config) -> CargoResult<(Option<(String, String)>, String)> { - let mut process = try!(util::process(cfg.rustc())); + let mut process = try!(util::process(cfg.rustc(), cfg.cwd())); process.arg("-") .arg("--crate-name").arg("_") .arg("--crate-type").arg("dylib") diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/engine.rs index 41a3188bb..2ce002962 100644 --- a/src/cargo/ops/cargo_rustc/engine.rs +++ b/src/cargo/ops/cargo_rustc/engine.rs @@ -40,10 +40,10 @@ impl CommandPrototype { -> CargoResult { Ok(CommandPrototype { builder: try!(match ty { - CommandType::Rustc => process(config.rustc()), - CommandType::Rustdoc => process(config.rustdoc()), + CommandType::Rustc => process(config.rustc(), config.cwd()), + CommandType::Rustdoc => process(config.rustdoc(), config.cwd()), CommandType::Target(ref s) | - CommandType::Host(ref s) => process(s), + CommandType::Host(ref s) => process(s, config.cwd()), }), ty: ty, }) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 75ee24c2d..f9b6bf52b 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -20,7 +20,7 @@ use util::config; use util::paths; use util::{CargoResult, human, ChainError, ToUrl}; use util::config::{Config, ConfigValue, Location}; -use util::important_paths::find_root_manifest_for_cwd; +use util::important_paths::find_root_manifest_for_wd; pub struct RegistryConfig { pub index: Option, @@ -252,7 +252,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> { let name = match opts.krate { Some(ref name) => name.clone(), None => { - let manifest_path = try!(find_root_manifest_for_cwd(None)); + let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd())); let pkg = try!(Package::for_path(&manifest_path, config)); pkg.name().to_string() } @@ -312,7 +312,7 @@ pub fn yank(config: &Config, let name = match krate { Some(name) => name, None => { - let manifest_path = try!(find_root_manifest_for_cwd(None)); + let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd())); let pkg = try!(Package::for_path(&manifest_path, config)); pkg.name().to_string() } diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index de5302f6f..8b2b09efc 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -31,11 +31,7 @@ pub struct Config { } impl Config { - pub fn new(shell: MultiShell) -> CargoResult { - let cwd = try!(env::current_dir().chain_error(|| { - human("couldn't get the current directory of the process") - })); - + pub fn new(shell: MultiShell, cwd: PathBuf) -> CargoResult { let mut cfg = Config { home_path: try!(homedir(cwd.as_path()).chain_error(|| { human("Cargo couldn't find your home directory. \ @@ -231,7 +227,7 @@ impl Config { } fn scrape_rustc_version(&mut self) -> CargoResult<()> { - self.rustc_info = try!(Rustc::new(&self.rustc)); + self.rustc_info = try!(Rustc::new(&self.rustc, self.cwd())); Ok(()) } diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index 1d6076b4b..bca7fc3c2 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,7 +1,6 @@ -use std::env; use std::fs; use std::path::{Path, PathBuf}; -use util::{CargoResult, human, ChainError}; +use util::{CargoResult, human}; /// Iteratively search for `file` in `pwd` and its parents, returning /// the path of the directory. @@ -35,11 +34,8 @@ pub fn find_project_manifest(pwd: &Path, file: &str) -> CargoResult { } /// Find the root Cargo.toml -pub fn find_root_manifest_for_cwd(manifest_path: Option) +pub fn find_root_manifest_for_wd(manifest_path: Option, cwd: &Path) -> CargoResult { - let cwd = try!(env::current_dir().chain_error(|| { - human("Couldn't determine the current working directory") - })); match manifest_path { Some(path) => { let absolute_path = cwd.join(&path); diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 628b681c1..08003de69 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -60,7 +60,9 @@ impl ProcessBuilder { pub fn get_args(&self) -> &[OsString] { &self.args } - pub fn get_cwd(&self) -> &Path { Path::new(&self.cwd) } + pub fn get_cwd(&self) -> &Path { + Path::new(&self.cwd) + } pub fn get_env(&self, var: &str) -> Option { self.env.get(var).cloned().or_else(|| Some(env::var_os(var))) @@ -106,7 +108,7 @@ impl ProcessBuilder { pub fn build_command(&self) -> Command { let mut command = Command::new(&self.program); - command.current_dir(&self.cwd); + command.current_dir(&self.get_cwd()); for arg in self.args.iter() { command.arg(arg); } @@ -129,11 +131,11 @@ impl ProcessBuilder { } } -pub fn process>(cmd: T) -> CargoResult { +pub fn process, U: AsRef>(cmd: T, cwd: U) -> CargoResult { Ok(ProcessBuilder { program: cmd.as_ref().to_os_string(), args: Vec::new(), - cwd: try!(env::current_dir()).as_os_str().to_os_string(), + cwd: cwd.as_ref().to_os_string(), env: HashMap::new(), }) } diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index 0a3fbf69b..a0cb1720f 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -14,8 +14,8 @@ impl Rustc { /// /// If successful this function returns a description of the compiler along /// with a list of its capabilities. - pub fn new>(path: P) -> CargoResult { - let mut cmd = try!(util::process(path.as_ref())); + pub fn new>(path: P, cwd: &Path) -> CargoResult { + let mut cmd = try!(util::process(path.as_ref(), cwd)); cmd.arg("-vV"); let mut ret = Rustc::blank(); diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index d171ec5eb..cad07c53b 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -8,22 +8,22 @@ pub struct HgRepo; pub struct GitRepo; impl GitRepo { - pub fn init(path: &Path) -> CargoResult { + pub fn init(path: &Path, _: &Path) -> CargoResult { try!(git2::Repository::init(path)); return Ok(GitRepo) } - pub fn discover(path: &Path) -> Result { + pub fn discover(path: &Path, _: &Path) -> Result { git2::Repository::discover(path) } } impl HgRepo { - pub fn init(path: &Path) -> CargoResult { - try!(try!(process("hg")).arg("init").arg(path).exec()); + pub fn init(path: &Path, cwd: &Path) -> CargoResult { + try!(try!(process("hg", cwd)).arg("init").arg(path).exec()); return Ok(HgRepo) } - pub fn discover(path: &Path) -> CargoResult { - try!(try!(process("hg")).arg("root").cwd(path).exec_with_output()); + pub fn discover(path: &Path, cwd: &Path) -> CargoResult { + try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output()); return Ok(HgRepo) } } -- 2.30.2